<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="format-detection" content="telephone=no"/>
		<title>身份认证</title>
		<link href="css/lt_common.css" rel="stylesheet" />
		<link href="css/validate.css" rel="stylesheet" />
	</head>
	<body>
	<div class='page' title='身份认证'>
		<div class='panel_content'>	
			<div class="container">
				<div class="identity_authentication">
					<form id='myform'>
						<input type="number" id="staff_number" name="staff_number" placeholder="员工工号" />
						<input type="text" id="name" name="name" placeholder="员工姓名" />
						<input type="hidden" id="openid" name="openid" value="" />
						<input type="hidden" id="state" name="state" value="" />
					</form>
				</div>
				<div class="login">
					<input type="button" value="马上验证" onclick="authentic()"/>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
<script src="js/common.js"></script>
<script src="js/jquery.js"></script>
<script>
	$('#openid').val(openid);
	var currid = getQueryString('currid');

	var state = getQueryString('state');
	$('#state').val(state);

	function authentic(){
		var staff_number = $('#staff_number').val();
		if(staff_number==''){
			alert('员工工号不能为空');
			return;
		}

		var name = $('#name').val();
		if(name==''){
			alert('员工姓名不能为空');
			return;
		}
		
		dosmt();
	}

	function dosmt(){
		//var API_URL_TEST = 'http://192.168.7.60:83/newchinalifeinterface/'
		if(state=='4'){
			$.ajax({
				cache: true,
				type: "POST",
				dataType: "JSON",
				url:API_URL+"manager/authentication",
				data:$('#myform').serialize(),
				async: false,
				error: function(request) {
					alert("Connection error");
				},
				success: function(jsonobj) {
				
					if(jsonobj.status.code == 0){
						//已认证,跳转主页,将UserId传入
						var myData = jsonobj.data[0];
						var userId = myData.staff_number;
						window.location = 'newCustomsClearance/growth_recorded.html?userId='+userId;
					}

					if(jsonobj.status.code == 2){
						//已认证,不是新人
						var myData = jsonobj.data[0];
						var userId = myData.staff_number;
						window.location = 'newCustomsClearance/growth_index.html?userId='+userId;
					}

					if(jsonobj.status.code == -1){
						alert('工号不存在或输入有误,请检查!');
						return;
					}
				  
				}
			});
		}else{
			$.ajax({
				cache: true,
				type: "POST",
				dataType: "JSON",
				url:API_URL+"agent/authentication",
				data:$('#myform').serialize(),
				async: false,
				error: function(request) {
					alert("Connection error");
				},
				success: function(jsonobj) {
				
					if(jsonobj.status.code == 0){
						//已认证,跳转主页,将openid传入
						var myData = jsonobj.data[0];
						var openid = myData.openid;
						if(state=='2'){
							if(currid!=null && currid!=''){
								window.location='teacherclub/status_detial.html?openid='+openid+'&detialId='+currid;
							}else{
								if(myData.agent_type=='1'){
									window.location = 'teacherclub/ranking_list.html?openid='+openid+'&user_status=2';
								}else{
									window.location = 'teacherclub/ranking_list.html?openid='+openid+'&user_status=1&agentid='+myData.id;
								}
							}
						}else{
							window.location = 'program/person_mainpage.html?openid='+openid;
						}
						
					}

					if(jsonobj.status.code == -1){
						alert('工号不存在或输入有误,请检查!');
						return;
					}

					if(jsonobj.status.code == 1){
						alert('对不起你不是组训社区成员!');
						return;
					}
				  
				}
			});
		}
	}
</script>